/*     */ package com.zimbra.cs.service.admin;
/*     */ 
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.soap.AdminConstants;
/*     */ import com.zimbra.common.soap.Element;
/*     */ import com.zimbra.cs.account.Entry;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.account.accesscontrol.AdminRight;
/*     */ import com.zimbra.cs.account.accesscontrol.RightCommand;
/*     */ import com.zimbra.cs.account.accesscontrol.RightCommand.ACE;
/*     */ import com.zimbra.cs.account.accesscontrol.RightCommand.Grants;
/*     */ import com.zimbra.cs.account.accesscontrol.Rights.Admin;
/*     */ import com.zimbra.cs.account.accesscontrol.TargetType;
/*     */ import com.zimbra.soap.ZimbraSoapContext;
/*     */ import com.zimbra.soap.admin.type.GranteeSelector.GranteeBy;
/*     */ import com.zimbra.soap.type.TargetBy;
/*     */ import java.util.HashSet;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import java.util.Set;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class GetGrants
/*     */   extends RightDocumentHandler
/*     */ {
/*     */   public Element handle(Element request, Map<String, Object> context)
/*     */     throws ServiceException
/*     */   {
/*  41 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/*  42 */     Provisioning prov = Provisioning.getInstance();
/*     */     
/*  44 */     String targetType = null;
/*  45 */     TargetBy targetBy = null;
/*  46 */     String target = null;
/*  47 */     Element eTarget = request.getOptionalElement("target");
/*  48 */     if (eTarget != null) {
/*  49 */       targetType = eTarget.getAttribute("type");
/*  50 */       if (TargetType.fromCode(targetType).needsTargetIdentity()) {
/*  51 */         targetBy = TargetBy.fromString(eTarget.getAttribute("by"));
/*  52 */         target = eTarget.getText();
/*     */       }
/*     */       
/*     */ 
/*  56 */       TargetType tt = TargetType.fromCode(targetType);
/*  57 */       Entry targetEntry = TargetType.lookupTarget(prov, tt, targetBy, target);
/*     */       
/*     */ 
/*     */ 
/*  61 */       checkRight(zsc, targetEntry, Rights.Admin.R_viewGrants);
/*     */     }
/*     */     
/*  64 */     String granteeType = null;
/*  65 */     GranteeSelector.GranteeBy granteeBy = null;
/*  66 */     String grantee = null;
/*  67 */     boolean granteeIncludeGroupsGranteeBelongs = true;
/*  68 */     Element eGrantee = request.getOptionalElement("grantee");
/*  69 */     if (eGrantee != null) {
/*  70 */       granteeType = eGrantee.getAttribute("type");
/*  71 */       granteeBy = GranteeSelector.GranteeBy.fromString(eGrantee.getAttribute("by"));
/*  72 */       grantee = eGrantee.getText();
/*  73 */       granteeIncludeGroupsGranteeBelongs = eGrantee.getAttributeBool("all");
/*     */     }
/*     */     
/*  76 */     RightCommand.Grants grants = RightCommand.getGrants(prov, targetType, targetBy, target, granteeType, granteeBy, grantee, granteeIncludeGroupsGranteeBelongs);
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*  83 */     Set<String> OKedTarget = new HashSet();
/*  84 */     for (RightCommand.ACE ace : grants.getACEs()) {
/*  85 */       TargetType tt = TargetType.fromCode(ace.targetType());
/*     */       
/*  87 */       Entry targetEntry = TargetType.lookupTarget(prov, tt, TargetBy.name, ace.targetName());
/*  88 */       String targetKey = ace.targetType() + "-" + ace.targetId();
/*  89 */       if (!OKedTarget.contains(targetKey)) {
/*  90 */         checkRight(zsc, targetEntry, Rights.Admin.R_viewGrants);
/*  91 */         OKedTarget.add(targetKey);
/*     */       }
/*     */     }
/*     */     
/*  95 */     Element resp = zsc.createElement(AdminConstants.GET_GRANTS_RESPONSE);
/*  96 */     grants.toXML(resp);
/*  97 */     return resp;
/*     */   }
/*     */   
/*     */   public void docRights(List<AdminRight> relatedRights, List<String> notes)
/*     */   {
/* 102 */     relatedRights.add(Rights.Admin.R_viewGrants);
/* 103 */     notes.add("Needs a get attr right of zimbraACE on each the target entry.  Granting the " + Rights.Admin.R_viewGrants.getName() + " is one way to do it, " + "which will give the right on all target types.   Use inline right " + "if more granularity is needed.   See doc for the " + Rights.Admin.R_viewGrants.getName() + " right in zimbra-rights.xml for more details.");
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/admin/GetGrants.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */